<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\LoginRequest;

use Hash;
use DB;

class loginController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function ind()
    {
        return view('login.index');
    }

   
    public function dologin(LoginRequest $request)
    {   
        
        //获取post请求过来的值
        $username = $request ->username;

        // //查询users表条件是post请求的值获取一条数据
         $user = DB::table('users') -> where('username',$username) ->first();
         if(!empty($user)){
        //用Hash解密数据库里面的password check里面的第一个参数是post请求的password
        //check里面的第二个参数是users表里面的password    check里面相当于是一个判断
        //check里面的($request->passwd=$user->password)为真返回true 否则返回false
              $password = Hash::check($request->password,$user->password);

              if($password){
                 return view('login.user.index');
              }else{
                return view('login.create');

              }
         }else{
            return view('login.create');
         }
    }

}
